<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>自动跳转</title>
    <style>
      p {
        text-align: center;
      }
      span {
        color: red;`
      }
    </style>
  </head>
  <body>
    <p><span id="time">5</span>秒之后自动跳转到百度</p>
    <script>
      var second = 5;
      var time = document.getElementById("time");
      function showTime() {
        second--;
        if (second <= 0) {
          location.href = "https://www.baidu.com";
        }
        time.innerHTML = second + "";
      }
      setInterval(showTime, 1000);
    </script>
  </body>
</html>
